#import absl
import logging
logging.basicConfig(level=logging.INFO)
import ray
import calc_manager
from calc_manager.base.runnable import Runnable, runnable_task
from calc_manager.executor.exec import *
from calc_manager.operator import Operator, OperatorInfo, print_operator_info
from calc_manager.ray.ray_manager import RayManager
from calc_manager.ray.remote_task import RayRemoteRunnableTaskFatory
from calc_manager.task.localtask import DefaultTaskFactory

manager = RayManager(
    "ray://10.130.9.3:10001",
    {
        "runtime_env": {
            "py_modules": [calc_manager],
            "working_dir": "./operators_sample",
            # "pip": ["emoji", "numpy", "pynvim"],
        }
    },
)

local_operator_info_args = {
    "operator_name": "test_sample_add",
    "operator_path": "operators_sample/sample_add/add.py",
    "operator_func_entrypoint": "add",
    "operator_desc": "This is a test operator",
}
local_operator_info = OperatorInfo(**local_operator_info_args)
remote_local_info_args = {
    "operator_name": "test_sample_add",
    "operator_path": "sample_add/add.py",
    "operator_func_entrypoint": "add",
    "operator_desc": "This is a test operator",
}
remote_operator_info = OperatorInfo(**remote_local_info_args)

default_exec = DefaultExecutor()
local_task_result = exec_operator_task(
    default_exec,
    local_operator_info,
    DefaultTaskFactory(),
    param={"a": 1, "b": 2, "c": 3.3, "desc": "test", "test_list": [1, 2, 3]},
)

remote_task_result = exec_operator_task(
    manager,
    remote_operator_info,
    RayRemoteRunnableTaskFatory(),
    param={"a": 1, "b": 2, "c": 3.3, "desc": "test", "test_list": [1, 2, 3]},
)

print(f"local task result {local_task_result}")
print(f"remote task result {remote_task_result}")
